package edu.monash.fit2099.demo.conwayslife;

import java.util.Arrays;
import java.util.List;

import edu.monash.fit2099.engine.GameEngineException;
import edu.monash.fit2099.engine.actors.Actor;
import edu.monash.fit2099.engine.displays.Display;
import edu.monash.fit2099.engine.positions.DefaultGroundCreator;
import edu.monash.fit2099.engine.positions.GameMap;
import edu.monash.fit2099.engine.positions.World;

public class Application {

	public static void main(String[] args) {
		Display display = new Display();
		World world = new ConwaysWorld(display);

		try {
			DefaultGroundCreator groundFactory = new DefaultGroundCreator();
			groundFactory.registerGround('.', Dirt::new);
			groundFactory.registerGround('+', Tree::new);
			List<String> map = Arrays.asList(
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"......................................++........................................",
					".....................................++.........................................",
					"......................................+.........................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					"................................................................................",
					".........................................................................++.....",
					"........................................................................++.++...",
					".........................................................................++++...",
					"..........................................................................++....",
					"................................................................................");
			GameMap gameMap = new ConwayGameMap(groundFactory, map);
			world.addGameMap(gameMap);

			Actor player = new Player("Conways");
			world.addPlayer(player, gameMap.at(10, 10));

			world.run();
		}
	 catch (GameEngineException exception){
		// Game engine exceptions
		 display.println(exception.getMessage());
	} catch (Exception e) {
		// General exception, to help debugging.
		e.printStackTrace();
	}
	}
}
